package org.ats.mail;

import java.io.File;
import java.util.List;
import org.apache.activemq.command.ActiveMQDestination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

@Service("MailQueuer")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class MailQueuer{

	@Autowired
	ApplicationContext appContext;
	
	@Autowired
	private JmsTemplate atsJmsTemplate;
	
	@Autowired
	private ActiveMQDestination emailQDest;
	
	@Autowired
	private AtsMailPreperator atsMailPreperator;
	
	@Autowired
	private MailTemplateProcessing mtp;
	
	//@Autowired
	//private AtsMailSender atsMailSender;
	
	
	public JmsTemplate getAtsJmsTemplate() {
		return atsJmsTemplate;
	}
	public void setAtsJmsTemplate(JmsTemplate atsJmsTemplate) {
		this.atsJmsTemplate = atsJmsTemplate;
	}
	public ActiveMQDestination getEmailQDest() {
		return emailQDest;
	}
	public void setEmailQDest(ActiveMQDestination emailQDest) {
		this.emailQDest = emailQDest;
	}
	
	public AtsMailPreperator getAtsMailPreperator() {
		return atsMailPreperator;
	}
	public void setAtsMailPreperator(AtsMailPreperator atsMailPreperator) {
		this.atsMailPreperator = atsMailPreperator;
	}
	public void sendJMSMailMsg(MailTemplates mailTemp, List<String> mailToList, File attachment){

		MailContent mc = mtp.ProcessTemplate(mailTemp);
		mc.setMailToList(mailToList);
		mc.setAttachment(attachment);
		//sending to the Que using que specified (emailQDest)
		getAtsJmsTemplate().convertAndSend(getEmailQDest(), mc);
	}

}
